package com.hnkywl.sts.dao.kcgl;

import com.hnkywl.sts.entity.xsgl.Zkdmx;
import net.ruixin.orm.hibernate.SimpleHibernateTemplate;
import org.hibernate.Criteria;
import org.hibernate.criterion.CriteriaSpecification;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Property;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;


/**
 * Created with IntelliJ IDEA.
 * User: jerry
 * Date: 13-4-15
 * Time: 下午2:14
 * To change this template use File | Settings | File Templates.
 */
@Repository
public class ZkdmxDao extends SimpleHibernateTemplate<Zkdmx, Long> {
    public List<Map> findZkdmxList(Long zkdId) {
        Criteria criteria = getSession().createCriteria(Zkdmx.class)
                .createAlias("kh", "kh", CriteriaSpecification.LEFT_JOIN)
                .createAlias("newkh", "newkh", CriteriaSpecification.LEFT_JOIN)
                .createAlias("zkd", "zkd", CriteriaSpecification.LEFT_JOIN)
                .createAlias("kh.jtwz", "jtwz", CriteriaSpecification.LEFT_JOIN)
                .setProjection(Projections.projectionList()
                        .add(Property.forName("id").as("id"))
                        .add(Property.forName("kh.id").as("kh.id"))
                        .add(Property.forName("zkd.zkdh").as("zkd.zkdh"))
                        .add(Property.forName("kh.khbm").as("kh.khbm"))
                        .add(Property.forName("kh.wsdj").as("wsdj"))
                        .add(Property.forName("jtwz.id").as("jtwz.id"))
                        .add(Property.forName("jtwz.oldcode").as("jtwz.oldcode"))
                        .add(Property.forName("jtwz.code").as("jtwz.code"))
                        .add(Property.forName("jtwz.name").as("jtwz.name"))
                        .add(Property.forName("jtwz.cz").as("jtwz.cz"))
                        .add(Property.forName("jtwz.dw").as("jtwz.dw"))
                        .add(Property.forName("jtwz.th").as("jtwz.th"))
                        .add(Property.forName("jtwz.ggxh").as("jtwz.ggxh"))
                        .add(Property.forName("zkjs").as("zkjs"))
                        .add(Property.forName("zksl").as("zksl"))
                        .add(Property.forName("zcsl").as("zcsl"))
                        .add(Property.forName("zrsl").as("zrsl"))
                        .add(Property.forName("bz").as("bz"))
                ).add(Restrictions.eq("zkd.id", zkdId)).addOrder(Property.forName("jtwz.oldcode").asc())
                .setResultTransformer(CriteriaSpecification.ALIAS_TO_ENTITY_MAP);
        return (List<Map>) criteria.list();
    }
}


